package com.langcollab.languagementor.component
{
    import com.langcollab.languagementor.component.event.Event_CreditsBox;

    import flash.events.MouseEvent;

    import spark.components.supportClasses.SkinnableComponent;
    import spark.components.supportClasses.StyleableTextField;

    [Event( name="creditsLinkClick", type="com.langcollab.languagementor.component.event.Event_CreditsBox")]

    public class CreditsBox extends SkinnableComponent
    {

        public var linkText:String;

        public var titleText:String;

        [SkinPart(required="true")]
        public var creditsLink:StyleableTextField;        

        public function CreditsBox()
        {
            super();
        }

        override protected function partAdded(partName:String, instance:Object):void
        {
            super.partAdded(partName, instance);
            if(instance == creditsLink)
            {
                creditsLink.text = linkText;
                creditsLink.addEventListener(MouseEvent.CLICK, onCreditsLinkClick);
            }
        }

        override protected function partRemoved(partName:String, instance:Object):void
        {
            super.partRemoved(partName, instance);
            if(instance == creditsLink)
            {
                creditsLink.removeEventListener(MouseEvent.CLICK, onCreditsLinkClick);
            }
        }

        private function onCreditsLinkClick(event:MouseEvent):void
        {
            dispatchEvent(new Event_CreditsBox(Event_CreditsBox.CREDITS_LINK_CLICK));
        }
    }
}


